/* $Header: wkfutil.h,v 2.2 01/10/02 10:30:47 przybyls Exp $ */



/***********************************************************************/
/* INCLUDE FILE NAME: wkfutil.h                                        */
/* ==================                                                  */
/*                                                                     */
/* Author:  Bob Cook                                                   */
/*                                                                     */
/* COMMENT:                                                            */
/*          Include file for the workfile operations                   */
/*                                                                     */
/*                                                                     */
/***********************************************************************/

#ifndef WKF_UTIL_H
#define WKF_UTIL_H

/*****************************/
/*   IFDEFS                  */
/*****************************/


/*****************************/
/*   SYMBOLIC CONSTANTS      */
/*****************************/

/*****************************/
/*   MACROS                  */
/*****************************/

/*****************************/
/*   TYPEDEFS                */
/*****************************/


#define  MAX_BUILD_WF_TABLE_SIZE 256  /* max number of entries in wkfile */
#define  MAX_WF_TX_SIZE 480   /* max num of bytes in each transmission of */
                              /*  the wkfile (does not include msg header) */
#define  WKFILE_SIZE    3072     /* length of download workfile buffer */



typedef struct
{
   TRUE_FALSE (*UseCmd)(void);
   TRUE_FALSE  gc_param;
   TRUE_FALSE  als_param;
   const INT16 cmd_size;
   BIT8  cmd_string[20];
} BUILD_WF_ENTRY_TYPE;


/* Define data structures for downloading a workfile. */
typedef  struct
{
    BIT8    *p_buffer;        /* ptr to next available location in buffer */
    U_INT16  length;          /* length of buffer */
    BIT8     install_request; /* signals a request for install workfile */
    BIT8     install_done;    /* signals that the workfile is installed */
    BIT8    *p_install_begin; /* ptr to point in buffer to start install */
    U_INT16  install_len;  /* number of bytes to install */
    BIT8     hex_crc[5];        /* 16 bit crc downloaded with workfile */
    BIT8     buffer[WKFILE_SIZE];   /* command strings */
}  DWNLD_WKFILE_TYPE;

/* Define data structures for uploading a workfile. */
typedef  struct
{
    BIT8    *p_buffer;         /* ptr to next available location in buffer */
    U_INT16  length;           /* actual length of workfile */
    BIT8    *p_entry[MAX_BUILD_WF_TABLE_SIZE]; /* ptr to each wkfile entry */
                               /* add 1 since last ptr is end of wkfile */
    U_INT16  total_entries;    /* actual number of entries in workfile */
    U_INT16  max_len;          /* maximum length of buffer holding wkfile */
    BIT8    *crc_loc;          /* location for crc (for internal wkfiles) */
    BIT8     create_request;   /* signals a request to create a workfile */
    BIT8     create_done;      /* signals that the workfile was created */
    BIT8     successful;       /* indicates workfile successfully loaded */
    BIT8     hex_crc[5];       /* 16 bit crc of all previous bytes of WF */
    WKFILE_CONTENTS contents;  /*  wkfile contain GC only ALS only or both */
    BIT8     buffer[WKFILE_SIZE];   /* command strings */
}  UPLD_WKFILE_TYPE;


/*****************************/
/*   EXTERN                  */
/*****************************/

extern IN_MSG_CB_TYPE  Wkfile_CB;   /* variables used in Wkfile for Scan */

#  pragma SECTION DATA=DRam
extern  DWNLD_WKFILE_TYPE   Dwnld_wkfile[4];
extern  UPLD_WKFILE_TYPE   Upld_wkfile[4];
#  pragma SECTION UNDO


/*****************************/
/*   FUNCTION PROTOTYPES     */
/*****************************/

void BuildWkFile(BIT8 *wf_loc,BIT8 *crc_loc,WKFILE_CONTENTS wkfile_contents, U_INT16 chan);
U_INT16 UpldWFEntrySize(U_INT16 entry, U_INT16 chan);
void CreateWkFileEntry(IN_MSG_CB_TYPE  *msg);
void InstallWkFile(BIT8  *p_begin, U_INT16 length, U_INT16 chan);
void CheckAndExecInstallWkFile(U_INT16 chan);
INT16 CreateWkfile(BIT8  *p_begin, U_INT16 max_length,BIT8  *crc_loc, WKFILE_CONTENTS wkfile_contents, U_INT16 chan);
void CheckAndExecCreateWkFile(void);
BIT8 MakeWkfile(BIT8  *p_begin, U_INT16 max_length,BIT8  *crc_loc,WKFILE_CONTENTS wkfile_contents, U_INT16 chan);
void CrcWkfile(BIT8  *p_begin, U_INT16 length,BIT8  *hex_crc);
UI_ERR  CheckWkfileCrc(BIT8  *p_begin, U_INT16 length, BIT8  *hex_crc);




#endif
